package com.ate.testday1.presenter;

import com.ate.testday1.MainActivity;
import com.ate.testday1.base.Xia;
import com.ate.testday1.contract.MyContract;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * @author Ate
 * @description:
 * @date :2020/11/10 18:36
 */
public class MyPresenter implements MyContract.Presenter {
    MainActivity mainActivity;

    public MyPresenter(MainActivity mainActivity) {
        this.mainActivity = mainActivity;
    }

    @Override
    public void get() {
        goget(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                String body = response.body();
                Gson gson = new Gson();
                Xia xia = gson.fromJson(body, Xia.class);
                List<Xia.DataBean> data = xia.getData();
                mainActivity.onSuccess(data);
            }
        });
    }
    private void goget(StringCallback callback){
        OkGo.<String>get("http://www.qubaobei.com/ios/cf/dish_list.php?stage_id=1&limit=20&page=1")
                .execute(callback);
    }
}
